<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of 8868
 *
 * @author dragon.hu add @2016.2.23
 */
require_once 'BaseChannel.php';

//8868
class M8868 implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="FLSHMHSY20150928JNEJFBTYAKJBSQXZZEJN"; //appKey 
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		//cpid
		$cpId = '2245';
		
		$orderLog = new ChargeOrder();
		$orderLog->log("m8868", $_REQUEST);
		
		$request = file_get_contents("php://input");
		$bodyarr = json_decode($request, true);
		
		$orderId = $bodyarr['data']['orderId'];
		$gameId = $bodyarr['data']['gameId'];
		$serverId = $bodyarr['data']['serverId'];
		$suid = $bodyarr['data']['suid'];
		$roleId = $bodyarr['data']['roleId'];
		$payWay = $bodyarr['data']['payWay'];
		$amount = $bodyarr['data']['amount'];
		$callbackInfo = $bodyarr['data']['callbackInfo'];
		$orderStatus = $bodyarr['data']['orderStatus'];
		$failedDesc = $bodyarr['data']['failedDesc'];
		$sign = $bodyarr['sign'];
		
		$mysign = $cpId."amount=".$amount."callbackInfo=".$callbackInfo."failedDesc=".$failedDesc.
		"gameId=".$gameId."orderId=".$orderId."orderStatus=".$orderStatus."payWay=".$payWay."roleId=".$roleId.
		"serverId=".$serverId."suid=".$suid.$paymentKey;
		
		//echo " sign=$sign ";
		//echo " mysign=$mysign ";
		
		if($sign == md5($mysign)) 
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($orderStatus != 'S')
			 {
			 	$tmpstatus = STATUS_FAILD;
			 }
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $amount, $callbackInfo, "m8868", $platform,$orderId))
			{
				$ret="FAILURE";
				$orderLog->log("m8868",array("order"=>$callbackInfo,"money"=>$amount,"serverresult"=>"faild"));
			}
			else 
			{
				//支付成功
				$ret="SUCCESS";
				$orderLog->log("m8868",array("order"=>$callbackInfo,"money"=>$amount,"serverresult"=>"success"));
			}
		} 
		else 
		{
			$ret="FAILURE";
			$orderLog->log("m8868","  order:$callbackInfo  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}